/* 
 * 创建日期 2011-7-19
 *
 * 成都天和软件公司
 * 电话：028-85425861 
 * 传真：028-85425861-8008 
 * 邮编：610041 
 * 地址：成都市武侯区航空路6号丰德万瑞中心B座1001 
 * 版权所有
 */
package  org.fantasy.question.service.impl;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import  org.fantasy.cpp.core.dao.nutz.BaseDAO;
import  org.fantasy.common.util.ParamMap;
import  org.fantasy.question.pojo.QStatus;
import  org.fantasy.question.pojo.QType;
import  org.fantasy.question.pojo.StaffInfo;
import  org.fantasy.question.pojo.SysInfo;
import  org.fantasy.question.service.MaintainService;

/** 
 * <p>Title: MaintainServiceImpl</p>  
 * <p>Description: 用于进行系统信息，员工信息，问题类型，问题状态等边缘信息的维护</p>  
 * <p>Copyright: Copyright (c) 2011-7-19</p>  
 * @author 沈飞 
 * @version 1.0 
 */
@Service("maintainService")
public class MaintainServiceImpl implements MaintainService{

	@Autowired
	private BaseDAO baseDAO;

	@Override
	public QStatus getQStatus(int statusId) throws Exception {
		QStatus status = baseDAO.fetch(QStatus.class, statusId);
		return status;
	}

	@Override
	public QType getQType(int typeId) throws Exception {
		QType type = baseDAO.fetch(QType.class, typeId);
		return type;
	}

	@Override
	public StaffInfo getStaffInfo(Long staffId) throws Exception {
		StaffInfo staff = baseDAO.fetch(StaffInfo.class, staffId);
		return staff;
	}

	@Override
	public SysInfo getSysInfo(int sysId) throws Exception {
		SysInfo info = baseDAO.fetch(SysInfo.class, sysId);
		return info;
	}

	@Override
	public void saveQStatus(ParamMap<String, Object> params) throws Exception {
		if (!params.isValid("id")) {
			QStatus status = new QStatus();
			BeanUtils.copyProperties(status, params);
			status.setState("A");
			baseDAO.insert(status);
		} else {
			Long id = params.getLong("id");
			QStatus status = baseDAO.fetch(QStatus.class,id);
			BeanUtils.copyProperties(status, params);
			baseDAO.update(status);
		}
	}

	@Override
	public void saveQType(ParamMap<String, Object> params) throws Exception {
		if (!params.isValid("id")) {
			QType type = new QType();
			BeanUtils.copyProperties(type, params);
			type.setState("A");
			baseDAO.insert(type);
		} else {
			Long id = params.getLong("id");
			QType type = baseDAO.fetch(QType.class,id);
			BeanUtils.copyProperties(type, params);
			baseDAO.update(type);
		}
	}

	@Override
	public void saveStaffInfo(ParamMap<String, Object> params) throws Exception {
		if (!params.isValid("id")) {
			StaffInfo staff = new StaffInfo();
			BeanUtils.copyProperties(staff, params);
			staff.setState("A");
			baseDAO.insert(staff);
		} else {
			Long id = params.getLong("id");
			StaffInfo staff = baseDAO.fetch(StaffInfo.class,id);
			BeanUtils.copyProperties(staff, params);
			baseDAO.update(staff);
		}
	}

	@Override
	public void saveSysInfo(ParamMap<String, Object> params) throws Exception {
		if (!params.isValid("id")) {
			SysInfo sysInfo = new SysInfo();
			BeanUtils.copyProperties(sysInfo, params);
			sysInfo.setState("A");
			baseDAO.insert(sysInfo);
		} else {
			Long id = params.getLong("id");
			SysInfo sysInfo = baseDAO.fetch(SysInfo.class,id);
			BeanUtils.copyProperties(sysInfo, params);
			baseDAO.update(sysInfo);
		}
	}

}
